#!/usr/bin/node

const log=console.log;
//占256个字节
let buf1=new Buffer(256);
buf1[0]=0;

log(`buf1 length:${buf1.length}\n`);
log('\nbuf1:',buf1);

for(let i=0;i<256;i++){
  buf1[i]=i;
}
log('\nbuf1',buf1);

let buf2=buf1.slice(250,256);
log('\nbuf2:',buf2);

buf2.fill(0);
log('\nbuf2:',buf2);
log('\nbuf2\'s JSON:',buf2.toJSON());
log('\nbuf2\'s JSON:',JSON.stringify(buf2));

let arr=['a',0xba,0xdf,0x00,255,10];
let buf3=new Buffer(arr);
log('\nbuf3:',buf3.length,buf3);

let str='hello world';
let buf4=new Buffer(str);
log('\nbuf4:',buf4.lenght,buf4);

buf4.copy(buf3,0,0,buf3.length);
log('\nbuf3:',buf3.length,buf3);

let sti = '你好 wangding';
let buf5 = new Buffer(sti,'utf8');
log('\nbuffer length:',buf5.length);
log('buffer content:',buf5);
log('string length:',sti.length);
